package com.bwstudio.demo.provider.controller;

import org.apache.commons.lang3.StringUtils;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.alibaba.csp.sentinel.annotation.SentinelResource;
import com.bwstudio.common.unires.annotation.ResponseResult;
import com.bwstudio.common.unires.exception.BusinessException;

@ResponseResult
@RestController
@RequestMapping(produces = MediaType.APPLICATION_JSON_VALUE)
public class EchoController {
	
	/**
	 * 服务端限流后，会抛出服务端错误com.alibaba.csp.sentinel.slots.block.flow.FlowException，
	 * @param string
	 * @return
	 */
//	@SentinelResource("echo")
    @GetMapping(value = "/echo/{string}")
    public String echo(@PathVariable String string) {
		if(StringUtils.contains(string, "0")) {
			throw new BusinessException(ResponseCodeEnum.PARAMETER_ILLEGAL);
		}
        return "Hello " + string;
    }
}